require('./Pagedgzsmain.less');
import Reflux from 'reflux';
import ReactMixin from 'react-mixin';
import Actions from './Actions'
import Store from './Store';
import { Button,Page, Panel,PanelHeader, PanelBody, PanelFooter,ButtonArea,
  MediaBox,Cells, Cell,CellHeader,MediaBoxTitle,MediaBoxHeader,
  MediaBoxDescription,MediaBoxBody,MediaBoxInfo,MediaBoxInfoMeta,PullToRefresh,
  CellBody,CellFooter,Toast, Form,FormCell,Radio,Gallery,GalleryDelete,
  Uploader,TextArea,ActionSheet,Flex,FlexItem,SearchBar} from  'react-weui/build/packages'
import {Control} from 'react-keeper';
import yuanlinlvhua  from './../../../assets/img/园林绿化.png';
import ludeng  from './../../../assets/img/路灯.png';
import jingguandeng  from './../../../assets/img/景观灯.png';
import anquanwenming  from './../../../assets/img/安全文明施工.png';
import 'weui';
import 'react-weui/build/packages/react-weui.css';
import DgzmMx from './../../../components/dgzsmx';

class Dgzsmain extends React.Component {

  constructor(props) {
    super(props);
    this.handleSubmit = this.handleSubmit.bind(this);
    this.handleCancel = this.handleCancel.bind(this);
    this.loadData = this.loadData.bind(this);
  }

  loadData(resolve) {
    Actions.loadData(resolve);
  }

  handleSubmit(text) {
    Actions.handleSubmit(text);
  }

  handleCancel() {
    Actions.handleCancel();
  }

  render() {
    return (
      <Page infiniteLoader={false} ptr={false}>
        <SearchBar onChange={this.handleSubmit}
                   onCancel={this.handleCancel}
                   defaultValue={this.state.dgzsmain.searchText}
                   placeholder="搜索">

        </SearchBar>

        <div
          style={{display:  this.state.dgzsmain.searchDivShow ? null : 'none',zIndex:'999',position:'absolute',width:'100%',height: '100vh', overflow: 'scroll',backgroundColor:'#fff'}}>
          <Panel style={{marginTop: 0 }}>
            <PanelHeader>
              搜索结果:
            </PanelHeader>
            <PanelBody>
              {this.state.dgzsmain.searchData.map((item, i)=> {
                return (
                  <MediaBox type="appmsg" onClick={(e) =>
                        {Control.go('/dgzshome/edit',
                          {dataDetail:item
                          })}}>
                    <MediaBoxHeader>
                      {item.urlList.length > 0 ? <img src={item.urlList[0]}/> : <img src={item.suggesttype==1?ludeng:
                           item.suggesttype==2?jingguandeng:
                        item.suggesttype==3?anquanwenming:
                          item.suggesttype==4?yuanlinlvhua:null}/>}
                    </MediaBoxHeader>
                    <MediaBoxBody>
                      <MediaBoxTitle>{item.title}</MediaBoxTitle>
                      <MediaBoxDescription>
                        {item.viewdesc}
                      </MediaBoxDescription>
                      <MediaBoxInfo>
                        <MediaBoxInfoMeta>{item.createdTime}</MediaBoxInfoMeta>
                        <MediaBoxInfoMeta extra className="zt-color">{
                          item.datastatus == 2 ? '已撤销' :
                            item.viewstatus == 1 ? '已提交待回复' : '已回复'
                        }</MediaBoxInfoMeta>
                      </MediaBoxInfo>

                    </MediaBoxBody>
                  </MediaBox>
                )
              })
              }
            </PanelBody>
          </Panel>
        </div>
        <PullToRefresh height={window.innerHeight-196}
                       onRefresh={this.loadData}>
          <DgzmMx item={this.state.dgzsmain.pdata.ld} suggesttype="1"/>
          <DgzmMx item={this.state.dgzsmain.pdata.jgd} suggesttype="2"/>
          <DgzmMx item={this.state.dgzsmain.pdata.yllh} suggesttype="3"/>
          <DgzmMx item={this.state.dgzsmain.pdata.aqsg} suggesttype="4"/>
        </PullToRefresh>

        <div style={{backgroundColor:'#fff'}}>
          <Cell>
            <CellBody>
              <ButtonArea>
                <Button onClick={()=> {Control.go("/dgzshome/list",{type:1})}} style={{
              backgroundColor:"rgba(22, 155, 213, 1)"
            }}>我的发现</Button>
                <Button onClick={()=> {Control.go("/dgzshome/edit",{dataDetail:null
                          })}} style={{
              backgroundColor:"rgba(22, 155, 213, 1)"
            }}>
                  我要说
                </Button>
              </ButtonArea>
            </CellBody></Cell>
        </div>
      </Page>
    );
  }

  componentWillMount() {
    Actions.loadData();
  }

  componentDidMount() {

  }


  shouldComponentUpdate(nextProps, nextState) {
    const thisProps = this.props || {},
      thisState = this.state.dgzsmain || {};
    if (Object.keys(thisProps).length !== Object.keys(nextProps).length ||
      Object.keys(thisState).length !== Object.keys(nextState).length) {
      return true;
    }

    for (const key in nextProps) {
      if (thisProps[key] !== nextProps[key]) {
        console.log(thisProps[key], nextProps[key]);
        return true;
      }
    }

    for (const key in nextState) {
      if (thisState[key] !== nextState[key]) {
        return true;
      }
    }
    return false;
  }

}

ReactMixin.onClass(Dgzsmain, Reflux.connect(Store, 'dgzsmain'));


export default Dgzsmain ;
